﻿using Dyao.Book.Application.TaskCenter.Manager;
using Dyao.Book.Contract;
using Foundation.Core;
using Microsoft.Extensions.DependencyInjection;

namespace Dyao.Book.Application
{
    public class TaskCenterManagerFactory : ITransientDependency
    {
        private readonly IServiceProvider _serviceProvider;

        public TaskCenterManagerFactory(IServiceProvider serviceProvider)
        {
            this._serviceProvider = serviceProvider;
        }

        public TManager Create<TManager>(TaskCenterDto taskCenterModel, bool isDistributedTask, CancellationToken cancellationToken)
            where TManager: TaskCenterManager
        {
            var service = _serviceProvider.GetService<TManager>();
            (service as ITaskCenterManagerIniter).Init(taskCenterModel, isDistributedTask, cancellationToken);

            return service;
        }
    }
}
